#include <func.h>
int main(int argc,char* argv[])
{
    ARGS_CHECK(argc,2);
    int ret;
    DIR* dir;
    dir=opendir(argv[1]);
    ERROR_CHECK(dir,NULL,"opendir");
    struct dirent *p;
    struct stat buf;
    char path_buf[1024]={0};
    while(p=readdir(dir))
    {
        if(!strcmp(p->d_name,".")||!strcmp(p->d_name,".."))
        {
            continue;
        }
        //文件夹需要拼接路径
        //所以此处只需用argv[1]
        sprintf(path_buf,"%s/%s",argv[1],p->d_name);
        ret=stat(path_buf,&buf);//获取文件状态(inode)信息
        ERROR_CHECK(ret,-1,"stat");
        //getpwuid(buf.st_uid)->pw_name,将uid转换为对应的用户名
        //ctime(&buf.st_mtime)+4获取常用的时间格式。+4是调整显示(去掉了星期几)
        printf("mode=%x,nlink=%ld,user=%s,gid=%s,size=%ld,time=%s\n",
        buf.st_mode,buf.st_nlink,getpwuid(buf.st_uid)->pw_name,
        getgrgid(buf.st_gid)->gr_name,buf.st_size,ctime(&buf.st_mtime)+4);       
    }
    closedir(dir);
    return 0;
}